<template>
	<view>
		<view class="header">
			<view class="u-flex-nowrap u-row-between u-flex page-font">
				<view class="u-flex">请输入条码信息或扫码</view>
			</view>
			<view class="u-flex-nowrap u-row-around u-flex page-font">
				<u-form class="u-flex u-flex-nowrap u-row-around">
					<u-form-item>
						<u-input v-model="scanResult" :type="type" height=50 placeholder="请输入条码信息" clearable />
					</u-form-item>
					<u-form-item class="u-flex u-row-center">
						<u-button size="medium" type="success" @click="getPlanNo">查询</u-button>
					</u-form-item>
				</u-form>
				<view class="u-flex-nowrap u-flex-col u-row-center u-col-center" @click="scanFun">
					<u-icon name="scan" color="#2979ff" size="100"></u-icon>
					<view class="$u-type-primary">点击扫码</view>
				</view>
			</view>
		</view>
		
		<view class="u-flex u-row-center">
			<u-button size="medium" type="success" @click="showModal">检验合格</u-button>
		</view>
		<!-- 条形码包含的工位信息 -->
		<view>
			<view class="list-item-wrapper" v-bind:id="index" v-for="(item,index) in form.checkScaninfoView" :key="index">
				<view class="list-item">
					<view>工序名称</view>
					<view>{{item.processName}}</view>
				</view>
				<view class="list-item">
					<view>责任人工号</view>
					<view>{{item.jobNumber}}</view>
				</view>
				<view class="list-item">
					<view>排产编号</view>
					<view>{{item.planNo}}</view>
				</view>
				<view class="list-item">
					<view>工段编号</view>
					<view>{{item.sectionNo}}</view>
				</view>
				<view class="list-item">
					<view>工位序号</view>
					<view>{{item.stationIdentifying}}</view>
				</view>
				<view class="list-item">
					<view>扫码时间</view>
					<view>{{item.scanTime}}</view>
				</view>
				<view class="u-flex u-row-center">
					<u-button size="medium" type="warning" @click="goFillForm(item.planNo,item.stationId, item.jobNumber, item.sectionNo, item.scanTime)">记录问题</u-button>
				</view>
			</view>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
		<u-modal v-model="show" :content="content" :async-close="true" :show-cancel-button="cancleBtn" @cancel="cancel" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
import { getECView, ecPass } from '../../../utils/index.js'
	export default {
		data() {
			return {
				form: {},								//通过条码查询到的数据
				scanResult: '',							//条形码信息
				show: false,							//弹出框是否显示的条件
				content: '是否确认所有工序均已合格',		//弹出框的提示信息
				cancleBtn: true							//弹出框的“取消”按钮显示条件
			}
		},
		methods: {
			// 点击按钮，启用扫码函数
			scanFun() {
				let that = this
				uni.scanCode({
					onlyFromCamera: true,
					success: function (res) {
						that.scanResult = res.result
						that.getPlanNo()
					},
					fail() {
						console.log('识别失败')
					}
				})
			},
			// 弹出框“确认”绑定的函数
			// 在调用提交函数后关闭弹出框
			confirm() {
				this.allMeetStandard()
				this.show = false
			},
			// 弹出框“取消”绑定的函数
			// 关闭弹出框
			cancel() {
				this.show = false
			},
			// 打开弹出确认框
			showModal() {
				this.show = true
			},
			// 通过条形码获取planNo，随后与条形码内容一起发到后台获取列表信息
			async getPlanNo() {
				const {data} = await getECView({deviceBarcode: this.scanResult})
				const errMsg = data.msg
				if(data.code == '1') {
					this.$refs.uTips.show({
						title: '查询成功',
						type: 'success',
						duration: '2000'
					})
				this.form = Object.assign({},data.data)						//将获取到的数据全部复制到form
				} else {
					this.$refs.uTips.show({
						title: errMsg,
						type: 'warning',
						duration: '2000'
					})
				}
			},
			// 产品所有工序合格函数
			async allMeetStandard() {
				let query = {}
				query = Object.assign({},this.form)						//将form数据复制给query
				delete query.checkScaninfoView							//后端不需要的数据从对象query中删除
				delete query.ecCheck
				delete query.produceName
				const {data} = await ecPass(query)
				const errMsg = data.msg
				if(data.code == '1') {
					this.$refs.uTips.show({
						title: '提交成功',
						type: 'success',
						duration: '2000'
					})
				} else {
					this.$refs.uTips.show({
						title: errMsg,
						type: 'warning',
						duration: '2000'
					})
				}
			},
			//将对应的数据传递到errorList页面
			goFillForm(planNo, stationId, jobNumber, sectionNo, scanTime) {
				uni.navigateTo({
					url:"../../../publicPage/qualityForm?planNo=" + planNo 
						 + '&stationId=' + stationId
						 + '&jobNumber=' + jobNumber 
						 + '&deviceBarcode=' + this.scanResult 							//该参数不在form中
						 + '&sectionNo=' + sectionNo
						 + '&checkStationId=' + this.form.checkStationId				//该参数不在form中
						 + '&scanTime=' + scanTime
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.page-font {
	font-size: 40rpx;
}
.list-item-wrapper {
	margin: 30rpx;
	background-color: #FFEFD5;
}
.list-item {
	display: flex;
	justify-content: space-between;
	font-size: 16px;
	margin: 10rpx 10rpx;
}
</style>
